package com.ljt.disruptordemo;

import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;

@Configuration
public class DisruptorConfig {
    @Bean
    public Disruptor<MyEvent> disruptor() {
        Disruptor<MyEvent> disruptor = new Disruptor<>(
                new MyEventFactory(),
                1024,
                Executors.defaultThreadFactory());

        // 绑定事件处理器
        disruptor.handleEventsWith(new MyEventHandler());
        disruptor.start();

        return disruptor;
    }
    @Bean
    public RingBuffer<MyEvent> ringBuffer(Disruptor<MyEvent> disruptor) {
        return disruptor.getRingBuffer();
    }
}